rm update
[EroBeats.git] / Djinn and Tonic - Erobeats / Settings.cpp
blob37227c931656c1cb522e0421b2306cdb2d019730
1 #include "Settings.h"
3 #include "ScreenNames.h"
4 #include "RescourceKeys.h"
6 Settings::Settings()
10 Settings::Settings(int* screenPointer, FileIO* filePntr, ResourceMaster* resourcePointer) {
12 screen = screenPointer;
13 fio = filePntr;
14 rsc = resourcePointer;
15 renderer = resourcePointer->rendPtr;
17 font = new Fonts(0, rsc);
18 outlineAnimation = new Animation(rsc->gameAnimations.at(WhiteBlueBG));
19 settings = fio->loadUserData(3);
21 initializeTextures();
23 gameLoop();
27 Settings::~Settings()
31 void Settings::destroyFonts() {
32 //don't destroy rsc textures
33 SDL_DestroyTexture( textResolution);
34 // SDL_DestroyTexture( textLarge);
35 SDL_DestroyTexture( textMedium);
36 // SDL_DestroyTexture( textSmall);
37 SDL_DestroyTexture( textBGMLevel);
38 SDL_DestroyTexture( textSFXLevel);
39 SDL_DestroyTexture( languageTitle);
40 SDL_DestroyTexture( languageEN);
41 SDL_DestroyTexture( languageFR);
42 SDL_DestroyTexture( languageFR);
43 SDL_DestroyTexture( languageJP);
44 SDL_DestroyTexture( textQuit);
45 SDL_DestroyTexture( textClear);
48 void Settings::initializeTextures() {
50 destroyFonts();
52 int textSizeX = font->prcnt(0.12, 'x');
53 int textSizeY = font->prcnt(0.12, 'y');
55 int column1 = font->prcnt(0.10, 'x');
56 int column2 = font->prcnt(0.30, 'x');
57 int column3 = font->prcnt(0.50, 'x');
59 int row1 = 0;
60 int row2 = font->prcnt(0.12, 'y');
61 int row3 = font->prcnt(0.25, 'y');
62 int row4 = font->prcnt(0.375, 'y');
63 int row5 = font->prcnt(0.50, 'y');
64 int row6 = font->prcnt(0.65, 'y');
65 int row7 = font->prcnt(0.80, 'y');
67 font->loadFont(SDL_Color{ 200,200,200,00 }, rsc->gameText.at(ResText), 2);
68 textResolution = font->getTexture();
69 rectResolution = { column1, row1, textSizeY * 2, textSizeX };
71 //font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(ResLargeText), 2);
72 //textLarge = font->getTexture();
73 //rectLarge = { column1, row2 , textSizeY, textSizeX };
75 font->loadFont(SDL_Color{ 255,255,255,00 }, rsc->gameText.at(ResMediumText), 2);
76 textMedium = font->getTexture();
77 rectMedium = { column2, row2 , textSizeY * 2, textSizeX };
79 //font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(ResSmallText), 2);
80 //textSmall = font->getTexture();
81 //rectSmall = { column3, row2 , textSizeY, textSizeX };
83 font->loadFont(SDL_Color{ 200,200,200,00 }, rsc->gameText.at(SFXText), 2);
84 textSFXLevel = font->getTexture();
85 rectSFXLevel = { column1, row3 , textSizeY * 2, textSizeX };
87 textSFXIcon = rsc->gameGraphics.at(SFXIcon);
88 rectSFXIcon = { column1, row4 , textSizeY, textSizeX };
90 SDL_SetTextureBlendMode(textBars, SDL_BLENDMODE_BLEND);
91 textBars = rsc->gameGraphics.at(GenericBar);
93 settings = fio->loadUserData(3);
95 //SCREENRES SFXVOL BGMVOL LANGUAGE
96 if (settings % 1000 / 100 == 1) {
97 displayNumberSFX = 1;
99 else if (settings % 1000 / 100 == 2) {
100 displayNumberSFX = 2;
102 else if (settings % 1000 / 100 == 3) {
103 displayNumberSFX = 3;
105 else if (settings % 1000 / 100 == 4) {
106 displayNumberSFX = 4;
108 else {
109 displayNumberSFX = 2;
112 font->loadFont(SDL_Color{ 200,200,200,00 }, rsc->gameText.at(BGMText), 2);
113 textBGMLevel = font->getTexture();
114 rectBGMLevel = { column3, row3, textSizeY * 2, textSizeX };
116 textBGMIcon = rsc->gameGraphics.at(BGMIcon);
117 rectBGMIcon = { column3, row4, textSizeY, textSizeX };
121 //SCREENRES SFXVOL BGMVOL LANGUAGE
122 if (settings % 100 / 10 == 1) {
123 displayNumberBGM = 1;
125 else if (settings % 100 / 10 == 2) {
126 displayNumberBGM = 2;
128 else if (settings % 100 / 10 == 3) {
129 displayNumberBGM = 3;
131 else if (settings % 100 / 10 == 4) {
132 displayNumberBGM = 4;
134 else {
135 displayNumberBGM = 2;
138 textBars = rsc->gameGraphics.at(GenericBar);
139 SDL_SetTextureBlendMode(textBars, SDL_BLENDMODE_BLEND);
140 for (int i = 0; i < 4; i++) {
141 BGMBarLocations[i] = { column1 + font->prcnt(0.09, 'x') + 20 * i, row4 + font->prcnt(0.01, 'y'), font->prcnt(0.01, 'x'), font->prcnt(0.125, 'y') };
143 for (int i = 0; i < 4; i++) {
144 SFXBarLocations[i] = { column3 + font->prcnt(0.09, 'x') + 20 * i, row4 + font->prcnt(0.01, 'y'), font->prcnt(0.01, 'x'), font->prcnt(0.125, 'y') };
147 font->loadFont(SDL_Color{ 200,200,200,00 }, rsc->gameText.at(LanguageText), 2);
148 languageTitle = font->getTexture();
149 rectTitleLocation = { column1, row5, textSizeY * 2, textSizeX };
151 font->loadFont(SDL_Color{ 255,255,255,00 }, rsc->gameText.at(ENText), 2);
152 languageEN = font->getTexture();
153 rectENLocation = { column1, row6, textSizeY, textSizeX };
155 font->loadFont(SDL_Color{ 255,255,255,00 }, rsc->gameText.at(FRText), 2);
156 languageFR = font->getTexture();
157 rectFRLocation = { column2 , row6, textSizeY, textSizeX };
159 font->loadFont(SDL_Color{ 255,255,255,00 }, rsc->gameText.at(JPText), 2);
160 languageJP = font->getTexture();
161 rectJPLocation = { column3, row6, textSizeY, textSizeX };
163 font->loadFont(SDL_Color{ 255,255,255,00 }, rsc->gameText.at(BackText), 2);
164 textQuit = font->getTexture();
165 rectQuit = { column2, row7, textSizeY, textSizeX };
167 font->loadFont(SDL_Color{ 255,255,255,00 }, rsc->gameText.at(ClearText), 2);
168 textClear = font->getTexture();
169 rectClear = { column1, row7, textSizeY, textSizeX };
173 void Settings::update()
176 hoverLarge = false;
177 hoverMedium = false;
178 hoverSmall = false;
179 hoverQuit = false;
180 hoverClear = false;
181 hoverEN = false;
182 hoverJP = false;
183 hoverFR = false;
185 for (int i = 0; i < 4; i++) {
186 hoverSFXBar[i] = false;
187 hoverBGMBar[i] = false;
188 if (x > SFXBarLocations[i].x && x < (SFXBarLocations[i].w + SFXBarLocations[i].x) && y > SFXBarLocations[i].y && y < (SFXBarLocations[i].h + SFXBarLocations[i].y)) {
189 ////cout << "ovrSFX\n";
190 hoverSFXBar[i] = true;
192 if (x > BGMBarLocations[i].x && x < (BGMBarLocations[i].w + BGMBarLocations[i].x) && y > BGMBarLocations[i].y && y < (BGMBarLocations[i].h + BGMBarLocations[i].y)) {
193 ////cout << "ovrBGM\n";
194 hoverBGMBar[i] = true;
198 if (x > rectQuit.x && x < (rectQuit.x + rectQuit.w) && y > rectQuit.y && y < (rectQuit.y + rectQuit.h)) {
199 ////cout << "ovr4\n";
200 hoverQuit = true;
202 else if (x > rectClear.x && x < (rectClear.x + rectClear.w) && y > rectClear.y && y < (rectClear.y + rectClear.h)) {
203 cout << "ovr4\n";
204 hoverClear = true;
206 else if (x > rectENLocation.x && x < (rectENLocation.x + rectENLocation.w) && y > rectENLocation.y && y < (rectENLocation.y + rectENLocation.h)) {
207 //cout << "ovren\n";
208 hoverEN = true;
210 else if (x > rectFRLocation.x && x < (rectFRLocation.x + rectFRLocation.w) && y > rectFRLocation.y && y < (rectFRLocation.y + rectFRLocation.h)) {
211 //cout << "ovrfr\n";
212 hoverFR = true;
214 else if (x > rectJPLocation.x && x < (rectJPLocation.x + rectJPLocation.w) && y > rectJPLocation.y && y < (rectJPLocation.y + rectJPLocation.h)) {
215 //cout << "ovrjp\n";
216 hoverJP = true;
218 // else if (x > rectSmall.x && x < (rectSmall.x + rectSmall.w) && y > rectSmall.y && y < (rectSmall.y + rectSmall.h)) {
219 //cout << "ovr3\n";
220 // hoverSmall = true;
221 // }
222 else if (x > rectMedium .x && x < (rectMedium .x + rectMedium .w) && y > rectMedium .y && y < (rectMedium .y + rectMedium .h)) {
223 //cout << "ovr2\n";
224 //hoverMedium = true;
226 // else if (x > rectLarge.x && x < (rectLarge.x + rectLarge.w) && y > rectLarge.y && y < (rectLarge.y + rectLarge.h)) {
227 //cout << "ovr1\n";
228 // hoverLarge = true;
229 // }
231 int currentTime = SDL_GetTicks();
232 if (currentTime - clickCooldown > 500) {
233 if (mouseClicked && hoverLarge) {
234 //cout << "Fired1\n";
235 rsc->changeResolution("1280X1024");
236 font->updateWindow();
237 initializeTextures();
238 int temp = settings / 10000 * 10000;
239 settings = temp + settings % 1000 + 3000;
240 clickCooldown = SDL_GetTicks();
242 else if (mouseClicked && hoverMedium) {
243 //cout << "Fired2\n";
244 rsc->changeResolution("1000X800");
245 font->updateWindow();
246 initializeTextures();
247 int temp = settings / 10000 * 10000;
248 settings = temp + settings % 1000 + 2000;
249 clickCooldown = SDL_GetTicks();
251 else if (mouseClicked && hoverSmall) {
252 //cout << "Fired3\n";
253 rsc->changeResolution("600X480");
254 font->updateWindow();
255 initializeTextures();
256 int temp = settings / 10000 * 10000;
257 settings = temp + settings % 1000 + 1000;
258 clickCooldown = SDL_GetTicks();
260 else if (mouseClicked && hoverClear) {
261 //cout << "Fired6a\n";
263 MessageBox msgBox(screen, rsc, rsc->gameText.at(MessageBoxMainText), rsc->gameText.at(MessageBoxSubText), rsc->gameText.at(MessageBoxNoText), rsc->gameText.at(MessageBoxYesText));
264 if (msgBox.getResponse() == true) {
265 fio->eraseUserData();
266 hoverBGMBar[1] = true;
267 hoverSFXBar[1] = true;
269 hoverClear = false;
270 clickCooldown = SDL_GetTicks();
273 else if (mouseClicked && hoverQuit) {
274 //cout << "Fired6b\n";
276 //MessageBox msgBox(screen, rsc, rsc->gameText.at(MessageBoxMainText), rsc->gameText.at(MessageBoxNoText), rsc->gameText.at(MessageBoxYesText));
277 //if (msgBox.getResponse() == true) {
278 fio->saveUserData(settings, 3);
280 running = false;
281 *screen = MainMenuScreen;
283 else if (mouseClicked && hoverEN) {
284 reloadLanguage("EN");
285 int temp = settings / 10 * 10;
286 settings = temp + settings % 1 + 1;
288 else if (mouseClicked && hoverFR) {
289 reloadLanguage("FR");
290 int temp = settings / 10 * 10;
291 settings = temp + settings % 1 + 2;
293 else if (mouseClicked && hoverJP) {
294 reloadLanguage("JP");
295 int temp = settings / 10 * 10;
296 settings = temp + settings % 1 + 3;
298 for (int i = 0; i < 4; i++) {
299 if (mouseClicked &&hoverSFXBar[i]) {
300 displayNumberSFX = i + 1;
301 rsc->sptr->setVolume(displayNumberSFX);
302 int temp = settings / 1000 * 1000;
303 settings = temp + settings % 100 + 100 * (i + 1) ;
305 if (mouseClicked && hoverBGMBar[i]) {
306 displayNumberBGM = i + 1;
307 rsc->bptr->setVolume(displayNumberBGM);
308 int temp = settings / 100 * 100;
309 settings = temp + settings % 10 + 10 * (i + 1);
315 void Settings::play()
317 if (mouseClicked && (/*hoverLarge || hoverMedium || hoverSmall ||*/ hoverQuit || hoverFR || hoverEN || hoverJP || hoverSFXBar[1] || hoverSFXBar[2] || hoverSFXBar[3] || hoverSFXBar[0]) && !clickPlayedOnce) {
318 rsc->sptr->playSFX(0);
319 clickPlayedOnce = true;
321 else if(!(/*hoverLarge || hoverMedium || hoverSmall || */hoverQuit || hoverFR || hoverEN || hoverJP || hoverSFXBar[1] || hoverSFXBar[2] || hoverSFXBar[3] || hoverSFXBar[0])){
322 clickPlayedOnce = false;
325 if (hoverLarge) {
326 hoverAddress = &hoverLarge;
328 else if (hoverMedium) {
329 hoverAddress = &hoverMedium;
331 else if (hoverSmall) {
332 hoverAddress = &hoverSmall;
334 else if (hoverClear) {
335 hoverAddress = &hoverClear;
337 else if (hoverQuit) {
338 hoverAddress = &hoverQuit;
340 else if (hoverFR) { hoverAddress = &hoverFR; }
341 else if (hoverEN) { hoverAddress = &hoverEN; }
342 else if (hoverJP) { hoverAddress = &hoverJP; }
344 if (!playedOnce && (/*hoverLarge || hoverMedium || hoverSmall ||*/ hoverQuit || hoverClear || hoverFR || hoverEN || hoverJP ) || hoverAddress != hoverAddressOld) {
345 rsc->sptr->playSFX(1);
346 playedOnce = true;
348 else if (playedOnce && (/*hoverLarge || hoverMedium || hoverSmall || */hoverQuit || hoverClear || hoverFR || hoverEN || hoverJP)) {
349 playedOnce = true;
351 else {
352 playedOnce = false;
355 if (hoverLarge) {
356 hoverAddressOld = &hoverLarge;
358 else if (hoverMedium) {
359 hoverAddressOld = &hoverMedium;
361 else if (hoverSmall) {
362 hoverAddressOld = &hoverSmall;
364 else if (hoverQuit) {
365 hoverAddressOld = &hoverQuit;
367 else if(hoverClear ){ hoverAddressOld = &hoverClear; }
368 else if (hoverFR) { hoverAddressOld = &hoverFR; }
369 else if (hoverEN) { hoverAddressOld = &hoverEN; }
370 else if (hoverJP) { hoverAddressOld = &hoverJP; }
374 void Settings::render()
376 SDL_RenderClear(renderer);
378 SDL_RenderCopy(renderer, rsc->gameBG.at(T2BG), NULL, NULL);
380 bool hover1 = false;
381 bool hover2 = false;
383 if (hoverEN) {
384 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectENLocation);
386 else if (hoverFR) {
387 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectFRLocation);
389 else if (hoverJP) {
390 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectJPLocation);
392 else if (hoverClear) {
393 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectClear);
395 else if (hoverQuit) {
396 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectQuit);
398 /*else if (!hover1 && !hover2) {
399 if (hoverLarge) {
400 // SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectLarge);
402 else if (hoverMedium) {
403 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectMedium);
405 else if (hoverSmall) {
406 // SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectSmall);
410 SDL_RenderCopy(renderer, textResolution, NULL, &rectResolution);
412 // SDL_RenderCopy(renderer, textLarge, NULL, &rectLarge);
413 SDL_RenderCopy(renderer, textMedium, NULL, &rectMedium);
414 // SDL_RenderCopy(renderer, textSmall, NULL, &rectSmall);
416 SDL_RenderCopy(renderer, textSFXLevel, NULL, &rectSFXLevel);
417 SDL_RenderCopy(renderer, textBGMLevel, NULL, &rectBGMLevel);
419 SDL_RenderCopy(renderer, textSFXIcon, NULL, &rectSFXIcon);
420 SDL_RenderCopy(renderer, textBGMIcon, NULL, &rectBGMIcon);
422 for (int i = 0; i < displayNumberBGM; i++) {
423 SDL_SetTextureAlphaMod(textBars, 255);
424 SDL_RenderCopy(renderer, textBars, NULL, &BGMBarLocations[i]);
426 for (int i = displayNumberBGM; i < 4; i++) {
427 SDL_SetTextureAlphaMod(textBars, 100);
428 SDL_RenderCopy(renderer, textBars, NULL, &BGMBarLocations[i]);
430 for (int i = 0; i < displayNumberSFX; i++) {
431 SDL_SetTextureAlphaMod(textBars, 255);
432 SDL_RenderCopy(renderer, textBars, NULL, &SFXBarLocations[i]);
434 for (int i = displayNumberSFX; i < 4; i++) {
435 SDL_SetTextureAlphaMod(textBars, 100);
436 SDL_RenderCopy(renderer, textBars, NULL, &SFXBarLocations[i]);
439 SDL_SetTextureAlphaMod(outlineAnimation->frames.at(outlineAnimation->currentPosition), 100);
440 if (!hover1) {
441 for (int i = 0; i < 4; i++) {
442 if (hoverBGMBar[i]) {
443 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &BGMBarLocations[i]);
444 hover2 = true;
448 if (!hover2) {
449 for (int i = 0; i < 4; i++) {
450 if (hoverSFXBar[i]) {
451 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &SFXBarLocations[i]);
452 hover1 = true;
456 SDL_SetTextureAlphaMod(outlineAnimation->frames.at(outlineAnimation->currentPosition), 255);
458 SDL_RenderCopy(renderer, languageTitle, NULL, &rectTitleLocation);
459 SDL_RenderCopy(renderer, languageEN, NULL, &rectENLocation);
460 SDL_RenderCopy(renderer, languageFR, NULL, &rectFRLocation);
461 SDL_RenderCopy(renderer, languageJP, NULL, &rectJPLocation);
463 SDL_RenderCopy(renderer, textClear, NULL, &rectClear);
464 SDL_RenderCopy(renderer, textQuit, NULL, &rectQuit);
466 SDL_RenderPresent(renderer);
469 void Settings::close()
471 delete font;
472 for (int i = 0; i < outlineAnimation->animationSize; i++) {
473 SDL_SetTextureAlphaMod(outlineAnimation->frames.at(i), 255);
474 //std::cout << i << " Frame\n";
476 delete outlineAnimation;
477 destroyFonts();
480 void Settings::reloadLanguage(std::string lang) {
481 if(lang == "EN")
482 fio->loadLanguage("Language/EN.txt");
483 else if (lang == "FR")
484 fio->loadLanguage("Language/FR.txt");
485 else if (lang == "JP")
486 fio->loadLanguage("Language/JP.txt");
487 initializeTextures();